package com.test.receiver;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import com.test.bindings.InputMessageBinding;
import com.test.bindings.InputMessageBinding;
import com.test.model.CollectionRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.handler.annotation.Header;

import java.io.IOException;

/**
 * @Description:
 * @Author: zrk
 * @Date: 2019/12/5
 */
@Slf4j
@EnableBinding(InputMessageBinding.class)
public class CollectionReceiver {

    @StreamListener(InputMessageBinding.INPUT)
    //@StreamListener(value = InputMessageBinding.INPUT,condition = "headers['my-header']=='你的header'")

    public void handle(String value/*, @Header(AmqpHeaders.CHANNEL)Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag*/) throws IOException {
        //public void handle(String value) throws IOException {
        log.info("[消息] 接收到发送消息MQ: {}", value);
        //int i = 1 / 0;
        CollectionRequest request = JSON.parseObject(value, CollectionRequest.class);
        log.info("处理收集信息：" + request.toString());
        //channel.basicAck(deliveryTag, false);
    }
}
